new Vue({
    el: '#app',
    // mixins: [Query],//组件配置文件，路径/utils/components.js
    data() {
        return {
            nodeKey: '',
            colunmData: [],
            tableData: [],
            form: {
                Page: 1,
                Limit: 100,
                Condition: '',
            },
            Total: 0,
            loading: false,
            isUpdate: true,
        }
    },
    mounted() {
        let ls_URL = window.location.href;
        this.nodeKey = getQueryObject(ls_URL, "nodeKey");// 获取 nodeKey 参数
        this.getColumn();
    },
    computed: {
        JsonString() {
            return function (str) {
                const isArrayOrObject = (value) => value !== null && typeof value === 'object';
                if (isArrayOrObject(str)) {
                    try {
                        return JSON.stringify(str);
                    } catch (e) { }
                }
                return str;
            }
        }
    },
    methods: {
        handleSizeChange(newSize) {
            this.form.Page = 1;
            this.form.Limit = newSize;
            this.getList(this.form);
        },
        handleCurrentChange(newPage) {
            this.form.Page = newPage;
            this.getList(this.form);
        },
        getColumn() {
            this.loading = true;
            httpRequest({
                hostApi: BASE_URL1,
                url: '/generalQueryAllColumnByTableName',
                type: 'GET',
                data: {
                    TableName: this.nodeKey
                }
            }).then(res => {
                if (res.Status == 'success') {
                    this.colunmData = res.Data;
                    this.isUpdate = false;
                    this.$nextTick(() => {
                        this.isUpdate = true;
                    })
                    this.getList(this.form);
                } else {
                    this.$message({
                        message: '查询失败，请联系开发者!',
                        type: 'error'
                    })
                }
            }).catch(xhr => {
                this.loading = false;
                this.$message({
                    message: '系统错误，请联系开发者!',
                    type: 'error'
                })
            })
        },
        getList(data) {
            this.loading = true;
            httpRequest({
                hostApi: BASE_URL1,
                url: '/generalPaginationQueryByTableName',
                data: {
                    TableName: this.nodeKey,
                    ...data
                },
            }).then(res => {
                console.log(res);
                if (res.Status == 'success') {
                    this.Total = res.Total;
                    this.tableData = res.Data;
                    this.isUpdate = false;
                    this.$nextTick(() => {
                        this.isUpdate = true;
                    })
                } else {
                    this.$message({
                        message: '查询失败，请联系开发者!',
                        type: 'error'
                    })
                }
            }).catch(xhr => {
                this.$message({
                    message: '系统错误，请联系开发者!',
                    type: 'error'
                })
            }).finally(() => {
                this.loading = false;
            })
        },
        handleBack() {
            window.location.href = './index.html'
        }
    }
})